package com.rency.mtds.manager.spi.enums;

import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Optional;

/**
 * 主备类型
 * @author: caiyu.ren
 * Created on 2019/9/3 10:15
 * @version: V1.0.0
 * @since JDK 11
 */
@ApiModel("主备类型")
@Getter
@ToString
public enum MasterSlaveType {

    MASTER("m","主库"),
    SLAVE("s","从库"),
    ;

    private String code;

    private String msg;

    MasterSlaveType(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static MasterSlaveType get(String code){
        Optional<MasterSlaveType> optional = Arrays.stream(MasterSlaveType.values()).filter( kind -> kind.getCode().equalsIgnoreCase(code)).findFirst();
        return optional.orElse(null);
    }
}
